import Modal from "../modal";

if(Modal.type === '下发任务') {
  const formData = {...values.field}
  const params = {
    eventId: formData.eventId,
    createBy: formData.taskIssuer,
    taskIssuer: formData.taskIssuer,
    taskIssuDepart: formData.taskIssuDepart,
    taskReceiveType: formData.taskReceiveType,
    taskTitle: formData.taskTitle,
    receiveSystemCode: formData.code,
    taskTypeId: formData.taskTypeId,
    taskSite: formData.taskSite,
  }
  params.taskTypeName = Modal.state.taskTypeId?.find(v => v.value === formData.taskTypeId)?.name
  params.receiveSystemName = Modal.state.code?.find(v => v.value === formData.code)?.name
  params.taskStartTime = new Date(formData.taskTime?.split(' - ')[0]).getTime()
  params.taskEndTime = new Date(formData.taskTime?.split(' - ')[1]).getTime()
  const list = []
  Object.entries(formData).forEach(([key, value]) => {
    if (key.includes('taskItem')) {
      list.push({
        taskDesc: value
      })
    }
  })
  params.insertTaskSubRequestList = list

  const fileArray = []
  Modal.files.forEach(val => {
    fileArray.push(val.filePresignedUrl)
  })
  params.attachmentUrl = fileArray.join(',')
  console.log('params', params)
  //  this.onModalCloseClick()
  Modal.postDistributeTasksData(params)?.then(res => {
    if(res) {
      window.layer?.msg('任务下发成功')
      this.onModalCloseClick()
    }
  })
}